package com.buyingtickets.service.impl;

import com.buyingtickets.dao.OrderDao;
import com.buyingtickets.entity.Order;
import com.buyingtickets.entity.QueryParameter;
import com.buyingtickets.entity.Ticket;
import com.buyingtickets.service.OrderBiz;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author czl
 * @version 1.0
 * @description: TODO
 * @date 2021/6/25 10:05
 */
@Service
public class OrderBizImpl implements OrderBiz {
    @Resource
    private OrderDao orderDao;
    @Override
    public List<Order> queryAll() {
       return orderDao.queryAll();
    }


    @Override
    public List<Order> queryByQueryOrder(QueryParameter qp) {
        int size=qp.getRows();//每页显示几条
        int count=queryCountQueryOrder(qp);//带条件的总条数
        int countPage=count%size==0?(count/size):(count/size+1);//带条件总页数
        if(countPage==0){
            return null;

        }
        int page=qp.getPage();//当前页
        //上下容错
        page=page<1?1:page;
        page=page>countPage?countPage:page;
        qp.setPage(page);//当前页
        qp.setStart((page-1)*size);//偏移量
        qp.setPageCount(countPage);//总页数
        qp.setShangPage(page-1);
        qp.setXiaPage(page+1);
        qp.setCount(count);
        return orderDao.queryByQueryOrder(qp);
    }

    @Override
    public int queryCountQueryOrder(QueryParameter qp) {
        return orderDao.queryCountQueryOrder(qp);
    }

    @Override
    public Order queryByID(int id) {
        return orderDao.queryByID(id);
    }

    @Override
    public int update(Order order) {
        return orderDao.update(order);
    }

    @Override
    public int delete(int id) {
        return orderDao.delete(id);
    }

    @Override
    public List<Ticket> queryAllTicket() {

        return orderDao.queryAllTicket();
    }

    @Override
    public List<Ticket> queryByQueryTicket(QueryParameter qp) {
        int size=qp.getRows();//每页显示几条
        int count=queryCountQueryTicket(qp);//带条件的总条数
        int countPage=count%size==0?(count/size):(count/size+1);//带条件总页数
        if(countPage==0){
            return null;
        }
        int page=qp.getPage();//当前页
        //上下容错
        page=page<1?1:page;
        page=page>countPage?countPage:page;
        qp.setPage(page);//当前页
        qp.setStart((page-1)*size);//偏移量
        qp.setPageCount(countPage);//总页数
        qp.setShangPage(page-1);
        qp.setXiaPage(page+1);
        qp.setCount(count);
        return orderDao.queryByQueryTicket(qp);
    }

    @Override
    public int queryCountQueryTicket(QueryParameter qp) {
        return orderDao.queryCountQueryTicket(qp);
    }

    @Override
    public Ticket queryByTID(int id) {
        return orderDao.queryByTID(id);
    }

    @Override
    public int updateT(Ticket ticket) {
        return orderDao.updateT(ticket);
    }

    @Override
    public int deleteT(int id) {
        return orderDao.deleteT(id);
    }
}
